/*
* $Id: FamilyStore.java 292 2011-03-24 21:08:17Z volok-aleksej@yandex.ru $
*
* Copyright 2008-2010 by Volokitin Alexey
* All rights reserved
*
*/
package apiary.db;

import java.io.*;

/**
 * Family database
 * @author lexus
 */
public class FamilyStore extends DBStore
{
    /**
     * Container of family records
     * @author lexus
     */
    public class FamilyRecord extends DBRecord
    {
//------------------------------Types family------------------------------------
        public static final int TYPE_DEFAULT = 0;
        public static final int TYPE_PEDIGREE = 1;
        public static final int TYPE_BREEDING = 2;
        public static final int TYPE_FATHER = 3;
        public static final int TYPE_AMADOU = 4;
        public static final int TYPE_BARREN = 5;
        public static final int TYPE_QUEEN_CELL = 6;
        public static final int TYPE_QUEEN_CELL_SMALL = 7;
        public static final int TYPE_INDIVIDUAL_PROVINE = 8;
        public static final int TYPE_COMBINED_PROVINE = 9;
        public static final int TYPE_PACKET = 10;
        public static final int TYPE_NON_QUEEN = 11;
        public static final int TYPE_SWARM = 12;
        public static final int TYPE_USER = 13;

        /** Identificator of family */
        public int idFamily;
        /** Name of family */
        public String name;
        /** Identificator of point */
        public int idPoint;
        /** Type of family */
        public int typeFamily;
        /** Note about family */
        public String noteFamily;
        /** Identificator user's fields */
        public int idRecord;

        /**
         * Constructor
         */
        public FamilyRecord() {
            name = new String();
            noteFamily = new String();
        }

        /**
         * Gets byte array of record
         * @return byte array
         */
        public byte[] getData() {
            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                DataOutputStream dos = new DataOutputStream(baos);
                dos.writeInt(idFamily);
                dos.writeUTF(name);
                dos.writeInt(idPoint);
                dos.writeInt(typeFamily);
                dos.writeUTF(noteFamily);
                dos.writeInt(idRecord);
                return baos.toByteArray();
            } catch (IOException ex) {}
            return null;
        }
        /**
         * Sets byte array record.
         * Array will be parsed and all fields of it will be filled
         * @param dis data input stream
         */
        public void setData(DataInputStream dis) throws IOException{
                idFamily = dis.readInt();
                name = dis.readUTF();
                idPoint = dis.readInt();
                typeFamily = dis.readInt();
                noteFamily = dis.readUTF();
                idRecord = dis.readInt();
        }
    }

    /**
     * Constructor
     */
    public FamilyStore(){
        super("db_family");
    }

    /**
     * Gets new record
     * @return new record
     */
    public DBRecord getRecord() {
        return new FamilyRecord();
    }
}
